<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/10/22 0022
 * Time: 下午 5:54
 */

namespace app\index\controller;


use app\admin\model\CategoryModule;
use app\admin\model\NewsCate;
use app\admin\model\TopImg;
use think\Controller;
use think\Db;

class Base extends Controller
{
    protected function category(){
        $category = CategoryModule::getindex();
        $footer_logo = TopImg::where(['is_deleted'=>1,'status'=>1])->order('sort asc,id asc')->select();
        $link = json_decode(setting('link'),true);
        $contactus = json_decode(setting('contactus'),true);
        $news_cate = NewsCate::where(['is_deleted' => 1, 'status' => 1])->order('sort desc,id desc')->select();
        $news_title = Db::name('index_block')->where('id',1)->value('title');

        //热门课程
        $aryRecommend = Db::name('lesson')->where(['is_deleted' => 1, 'is_recommend' => 1,'type'=>12])->order('sort asc,id asc')->limit(0,4)->select();

        //获取当前一周要闻
        $aryRecommendNews = Db::name('news')->where(['is_deleted' => 1, 'status' => 1])->order('create_at DESC')->limit(0,4)->select();
        //延伸阅读
        $aryRecommendRead = Db::name('news')->where(['is_deleted' => 1, 'status' => 1, 'pid' => 1])->order('create_at DESC')->limit(0,4)->select();
        //随机推荐
        $aryRecommendRand = Db::name('news')->where(['is_deleted' => 1, 'status' => 1])->orderRaw('rand()')->limit(0,2)->select();

        parent::assign([
            'footer_logo'=>$footer_logo,
            'link'=>$link,
            'category'=>$category,
            'contactus'=>$contactus,
            'news_cate'=>$news_cate,
            'news_title'=>$news_title,
            'aryRecommend'=>$aryRecommend,
            'aryRecommendNews'=>$aryRecommendNews,
            'aryRecommendRead'=>$aryRecommendRead,
            'aryRecommendRand'=>$aryRecommendRand,
        ]);
    }
}